#!/bin/bash
ssv_phy=""
drv_name=""
key_word="SSV|RSV"

if [[ ${1} =~ "wlan" ]]; then
	wlan_dirs=/sys/class/net/${1}/device/ieee80211/
	if [ ! -e ${wlan_dirs} ]; then
		echo "Could not find the ${1}."
		exit 1;
	fi
	ssv_phy=`ls ${wlan_dirs}`
	drv_name=`ls /sys/class/ieee80211/${ssv_phy}/device/driver | grep -E $key_word`
else
	phy_dirs="/sys/class/ieee80211/*"

	for phy_dir in $phy_dirs; do
		if [ ! -d ${phy_dir}/device/driver ]; then
			exit 1;
		fi
		drv_name=`ls ${phy_dir}/device/driver | grep -E $key_word`
    	if [ ${drv_name} ]; then
    		ssv_phy=`basename $phy_dir`;
    		break;
    	fi
	done
fi


# excute CLI
if [ -z ${ssv_phy} ]; then
    echo SSV PHY device not found.;
    exit 1;
fi

ssv_debugfs_dir=/sys/kernel/debug/ieee80211/${ssv_phy}/${drv_name}
if [ ! -d $ssv_debugfs_dir ]; then
    echo SSV debugfs not found.;
    exit 1;
fi

cd $ssv_debugfs_dir

cat queue_status
cat hci/hw_txq_len

find . -name ampdu_tx_summary -exec cat {} \;

SSV_CMD_FILE=/proc/ssv/${ssv_phy}/ssv_cmd
if [ -f $SSV_CMD_FILE ]; then
    echo "hwq" > $SSV_CMD_FILE
    cat $SSV_CMD_FILE
fi
